package com.hmdp.MQ;

import com.hmdp.config.RabbitMQTopicConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class MQSender {
    private final RabbitTemplate rabbitTemplate;


    public static final String ROUTINGKEY = "seckill.message";

    public MQSender(RabbitTemplate rabbitTemplate, RabbitMQTopicConfig rabbitMQTopicConfig) {
        this.rabbitTemplate = rabbitTemplate;
    }

    /**
     * 发送秒杀消息
     * @param msg
     */
    public void sendSeckillMessage(String msg){
        log.info("发送消息"+msg);
        rabbitTemplate.convertAndSend(RabbitMQTopicConfig.EXCHANGE,ROUTINGKEY,msg);
    }
}
